<template>
    <div>
        <h2>转购19商统计</h2>
     <div class="buttoncon">
        <Button type="primary"   @click="go" >返回上一页</Button>
          <Col span="8">
         <span>日期：</span>
            <DatePicker type="daterange" placement="bottom-end" placeholder="选择日期" style="width: 200px" @on-change="change"></DatePicker>
        </Col>
    </div>
     <Table border :loading="loading" :columns="columns2"  :data="data2" class="totalls"></Table>
        <Table border :loading="loading" :columns="columns1"  :data="data1"></Table>
         <div class="pages">
            <Page :total="pageTotal" :current="pageNum" :page-size="pageSize" show-elevator show-total 
placement="top" @on-change="handlePage" @on-page-size-change='handlePageSize'></Page>
        </div>
    </div>
</template>
<script type="text/javascript">
export default {
            data(){
                return{
              loading: true,
                pageTotal: 0,
             pageNum: 1,
             pageSize: 7,
             SKU:' ',
             starttime:'',
             endtime:'',
                  columns2:[
                   {
                        title: '总和',
                        key: 'datetotal',
                        align: 'center'
           
                    },
                    {
                        title: '研习社',
                        key: 'yxsZsxy19count',
                        align: 'center'
           
                    },
                         {
                        title: '18商',
                        key: 'sxy18Zsxy19count',
                        align: 'center'
           
                    }   ,  {
                        title: '创新院',
                        key: 'cxyZsxy19count',
                        align: 'center'
           
                    },{
                        title: '研习社+18商',
                        key: 'yxsAndsxy18Zsxy19count',
                        align: 'center'
           
                    }  ,  
                     {
                        title: '研习社+创新院',
                        key: 'yxsAndcxyZsxy19count',
                        align: 'center'
           
                    },
                    {
                        title: '18商+创新院',
                        key: 'sxy18AndcxyZsxy19count',
                        align: 'center'
           
                    },
                        {
                        title: '研习社+18商+创新院',
                        key: 'yxsAndsxy18AndcxyZsxy19count',
                        align: 'center'
           
                    },
                     {
                        title: '总累计',
                        key: 'totalkist',
                        align: 'center'
                    }
              //        yxsZsxy19count:0,
              //  sxy18Zsxy19count:0,
              //  cxyZsxy19count:0,
              // yxsAndsxy18Zsxy19count:0,
              //  yxsAndcxyZsxy19count:0,
              //  sxy18AndcxyZsxy19count:0,
              //   yxsAndsxy18AndcxyZsxy19count:0
             ],
             data2:[],
                columns1: [
                    {
                        title: '日期',
                        key: 'date_z',
                        align: 'center',
                    },
                    {
                        title: '研习社',
                        key: 'ysxZsxy19',
                        align: 'center',
                                       render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                                  this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "yxs",
                                                            sku_z:"date_sxy19",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                                        }
                                    }
                                },  params.row.ysxZsxy19)
                          
                           
                        }
                
                    },
                      {
                        title: '18商',
                        key: 'sxy18Zsxy19',
                        align: 'center',
                           render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                                  this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "sxy",
                                                            sku_z:"date_sxy19",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                                        }
                                    }
                                },  params.row.sxy18Zsxy19)
                          
                           
                        }
             
                    },
                               {
                        title: '创新院',
                        key: 'cxyZsxy19',
                        align: 'center',
                                render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                                this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "cxy",
                                                            sku_z:"date_sxy19",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                        // window.location.href="information.html?sku=cxy&sku_z=date_sxy19&date_z="+params.row.date_z
                                        }
                                    }
                                },  params.row.cxyZsxy19)
                          
                           
                        }
                    },
                     {
                        title: '研习社+18商',
                        key: 'yxsAndsxy18Zsxy19',
                        align: 'center',
                                     render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                               this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "yxs-sxy",
                                                            sku_z:"date_sxy19",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                                        }
                                    }
                                },  params.row.yxsAndsxy18Zsxy19)
                          
                           
                        }
                    },
                    {
                        title: '研习社+创新院',
                        key: 'yxsAndcxyZsxy19',
                        align: 'center',
                             render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                                this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "yxs-cxy",
                                                            sku_z:"date_sxy19",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                                        }
                                    }
                                },  params.row.yxsAndcxyZsxy19)
                          
                           
                        }
                    },
                     {
                        title: '18商+创新院',
                        key: 'sxy18AndcxyZsxy19',
                        align: 'center',
                           render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                               this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "sxy-cxy",
                                                            sku_z:"date_sxy19",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                     
                                        }
                                    }
                                },  params.row.sxy18AndcxyZsxy19)
                          
                           
                        }
                    },
                     {
                        title: '研习社+18商+创新院',
                        key: 'yxsAndsxy18AndcxyZsxy19',
                        align: 'center',
                            render: 
                             (h, params) => {                          
                              return   h('a', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'     
                                    },
                                    style: {
                                        marginRight: '5px',

                                    },
                                    on: {
                                        click: () => {
                                          console.log(params.row.date_z)
                                             console.log(params)
                                                this.$router.push({
                                                          path: '/Catalog/information',
                                                          query: {
                                                            sku: "yxs-sxy-cxy",
                                                            sku_z:"date_sxy19",
                                                            date_z:params.row.date_z
                                                          }
                                                        })
                                        }
                                    }
                                },  params.row.yxsAndsxy18AndcxyZsxy19)
                          
                           
                        }
                    },
                     {
                        title: '累计',
                        key: 'conut',
                        align: 'center'
                    }
                ],
                data1: [],
                datacxy:{
                    datetotal:"合计",
                  yxsZsxy19count:0,
               sxy18Zsxy19count:0,
               cxyZsxy19count:0,
              yxsAndsxy18Zsxy19count:0,
               yxsAndcxyZsxy19count:0,
               sxy18AndcxyZsxy19count:0,
                yxsAndsxy18AndcxyZsxy19count:0,
                  totalkist:0
                }
                }
            },
     created(){
            this.SKU=this.$route.query.Skus;
  this.getTeacherMessages();
    },
 methods: {
// 日期改变--------------------------------------------------------
      change(key,v){
       console.log(key[0])
         this.starttime=key[0];
         this.endtime=key[1];
             if (key[0]!="") 
           {
             this.$Message.success('成功');
           }
         this.getTeacherMessages()
    },
  handlePage(value) {
      this.pageNum = value
      this.getTeacherMessages()
    },
    handlePageSize(value) {
      this.pageSize = value
      this.getTeacherMessages()
    },
      getTeacherMessages(){
         var that =this
        var pagenum=this.pageNum-1;
        if (this.starttime=="" || this.endtime=="") 
            {
                var URL=this.Util.URL()+'/v1/buy-stat/stat-daily?sku='+this.SKU+'&page='+pagenum+'&page_size='+this.pageSize
            }else{
                 var URL=this.Util.URL()+'/v1/buy-stat/stat-daily?sku='+this.SKU+'&page='+pagenum+'&page_size='+this.pageSize+'&date_from='+  this.starttime+'&date_end='+ this.endtime;
            }
    this.axios({
      method: 'get',
      url: URL
    })
    .then(function (response) {
        that.pageTotal= parseInt(response.data.data.total_count);
        // 总计---------------------------------------------------------
        console.log(response.data.data)
           that.data2.length=0;
        for (var i = 0; i < response.data.data.allCount.length; i++) {
           var  Data = response.data.data.allCount[i];
           console.log(Data)
           that.datacxy.yxsZsxy19count=parseInt(Data.yxsZsxy19)
           that.datacxy.sxy18Zsxy19count=parseInt(Data.sxy18Zsxy19)
           that.datacxy.cxyZsxy19count=parseInt(Data.cxyZsxy19)
           that.datacxy.yxsAndsxy18Zsxy19count=parseInt(Data.yxsAndsxy18Zsxy19)
           that.datacxy.yxsAndcxyZsxy19count=parseInt(Data.yxsAndcxyZsxy19)
           that.datacxy.sxy18AndcxyZsxy19count=parseInt(Data.sxy18AndcxyZsxy19)
           that.datacxy.yxsAndsxy18AndcxyZsxy19count=parseInt(Data.yxsAndsxy18AndcxyZsxy19)
        }
        that.datacxy.totalkist=parseInt(Data.yxsZsxy19)+parseInt(Data.sxy18Zsxy19)+parseInt(Data.cxyZsxy19)+parseInt(Data.yxsAndsxy18Zsxy19)+parseInt(Data.yxsAndcxyZsxy19)+parseInt(Data.sxy18AndcxyZsxy19)+parseInt(Data.yxsAndsxy18AndcxyZsxy19)
        that.data2.push({
        datetotal: that.datacxy.datetotal,
                  yxsZsxy19count:that.datacxy.yxsZsxy19count,
             sxy18Zsxy19count:that.datacxy.sxy18Zsxy19count,
              cxyZsxy19count:that.datacxy.cxyZsxy19count,
             yxsAndsxy18Zsxy19count:that.datacxy.yxsAndsxy18Zsxy19count,
                yxsAndcxyZsxy19count:that.datacxy.yxsAndcxyZsxy19count,
              sxy18AndcxyZsxy19count:that.datacxy.sxy18AndcxyZsxy19count,
               yxsAndsxy18AndcxyZsxy19count:that.datacxy.yxsAndsxy18AndcxyZsxy19count,
                totalkist:that.datacxy.totalkist
                })
       // response.data.data.push({
       //        date_z:"合计",
       //         ysxZsxy19: that.datacxy.ysxZsxy19count,
       //         sxy18Zsxy19:that.datacxy.sxy18Zsxy19count,
       //         cxyZsxy19: that.datacxy.cxyZsxy19count,
       //        yxsAndsxy18Zsxy19:that.datacxy.yxsAndsxy18Zsxy19count,
       //          yxsAndcxyZsxy19:that.datacxy.yxsAndcxyZsxy19count,
       //         sxy18AndcxyZsxy19:that.datacxy.sxy18AndcxyZsxy19count,
       //          yxsAndsxy18AndcxyZsxy19:that.datacxy.yxsAndsxy18AndcxyZsxy19count
       //       })
       // 数据列表---------------------------------------------------------
        that.data1.length=0;
        for (var i = 0; i < response.data.data.list.length; i++) {
             var  Data = response.data.data.list[i]
             console.log(Data)
             // console.log(Data.date_z)
             // console.log(response.data.data[i].sxy19Zyxs)
             // console.log( that.data1)
          that.data1.push({
            date_z:Data.date_z,
           ysxZsxy19:Data.yxsZsxy19,
            sxy18Zsxy19:Data.sxy18Zsxy19,
           cxyZsxy19:Data.cxyZsxy19,
            yxsAndsxy18Zsxy19:Data.yxsAndsxy18Zsxy19,
           yxsAndcxyZsxy19:Data.yxsAndcxyZsxy19,
            sxy18AndcxyZsxy19:Data.sxy18AndcxyZsxy19,
            yxsAndsxy18AndcxyZsxy19:Data.yxsAndsxy18AndcxyZsxy19,
            conut:parseInt(Data.yxsZsxy19)+parseInt(Data.sxy18Zsxy19)+parseInt(Data.cxyZsxy19)+parseInt(Data.yxsAndsxy18Zsxy19)+parseInt(Data. yxsAndcxyZsxy19)+parseInt(Data.sxy18AndcxyZsxy19)+parseInt(Data.yxsAndsxy18AndcxyZsxy19)
          } )
          // console.log( that.data1)
        }

 
        
    })
    .catch(function (error) {
      console.log(error)
    }).finally(() => this.loading = false)



      },
                  go() {
              this.$router.back(-1)
               // console.log(3333) 
            }
 }
       }
</script>
<style scoped>
 h2{
        text-align: center;
        margin-bottom: 10px;
     }
         .buttoncon{
      margin:16px 0;
        display: flex;
        justify-content: space-between;
     }
    .pages {
      margin:16px 0;
        display: flex;
        justify-content: flex-end;
     }
   .totalls{
        margin-bottom: 20px;
     }
</style>